<?php

//设置你的连接
$conn_args = array(
    'host' => 'localhost', 
    'port' => '5672', 
    'login' => 'jsapi', 
    'password' => '123456',
    'vhost' => 'applications');
$conn = new AMQPConnection($conn_args);
if ($conn->connect()) {
    echo "Established a connection to the broker \n";
}
else {
    echo "Cannot connect to the broker \n ";
}

//你的消息
$message = json_encode(array('Hello World!','php','rabbitmq'));
//创建channel
$channel = new AMQPChannel($conn);
//创建exchange
$ex = new AMQPExchange($channel);
$ex->setName('demo.exchange');//创建名字
$ex->setType(AMQP_EX_TYPE_DIRECT);
$ex->setFlags(AMQP_DURABLE);
//$ex->setFlags(AMQP_AUTODELETE);
//echo "exchange status:".$ex->declare();
echo "exchange status:".$ex->declareExchange();
echo "\n";

$routingkey='demo.key';
$ex->publish($message,$routingkey);

?>